#include<iostream>
#include<pthread.h>
#include<string>
#include<unistd.h>
#include <string.h>


//利用Linux原生线程库
void* run(void* args)
{
    std::string name = static_cast<const char*> (args);
    while(true)
    {
        std::cout<<"我是子线程,我的名字是："<<name<<std::endl;
        sleep(1);
    }
}

int main()
{
    pthread_t pid;
    int n = pthread_create(&pid,nullptr,run,(void*)"thread -1");
    if(n!=0)
    {
        std::cout<<"create pthread errno:"<<strerror(n)<<std::endl;
        return 0;
    }

    while(true)
    {
        std::cout<<"我是主线程"<<std::endl;
        sleep(1);
    }
    return 0;
}